package com.ego.product.web;

import com.ego.product.service.SkuInfoService;
import com.ego.product.vo.DetailVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.ExecutionException;

/**
 * @program: ego
 * @description: 商品详情
 * @author: KamTang
 * @create: 2022-12-09 14:33
 **/
@Controller
@Slf4j
public class DetailController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 展示商品（sku）详情
     */
    @GetMapping("/skuId={skuId}.html")
    public String detail(@PathVariable("skuId") String skuId, Model model) throws ExecutionException, InterruptedException {
        try {
            DetailVo detail = skuInfoService.detail(Long.parseLong(skuId));
            model.addAttribute("detail", detail);
        } catch (NumberFormatException e) {
            return "index";
        }
        return "detail";
    }
}
